#!/usr/bin/env groovy
def dockerName = "turbo-cloud/turbo-cloud-gateway-dev"
node {
    stage('checkout') {
        checkout scm
    }

    stage('check java') {
        sh "java -version"
    }

    stage('clean') {
        sh "chmod +x mvnw"
        sh "./mvnw clean"
    }

    stage('packaging') {
        sh "./mvnw -pl . -am package -Pprod -DskipTests"
        archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
    }

    def dockerImage
    stage('build docker') {
        sh "cp -R docker target/"
        sh "cp target/turbo-cloud-*.jar target/docker/"
        dockerImage = docker.build(dockerName, 'target/docker')
    }

    stage('run docker') {
        sh "docker run --name turbo-cloud-gateway-dev " +
                "-p 62001:62001 " +
                "-e SERVER_ACTIVE=dev " +
                "-e SERVER_IP=127.0.0.1 " +
                "-d ${dockerName}"
    }
}
